Add AdditionalFiles support to VSTHRD103 analyzer for excluding specific APIs#1465
Conversation
Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
- Add new file pattern for exclusion files in CommonInterest.cs - Modify VSTHRD103 analyzer to read additional files and check exclusions - Add comprehensive test cases for the new exclusion functionality - Update documentation to describe the new configuration option Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
- Add test for JoinableTaskFactory.Run exclusion - Include JTF.Run in test exclusion file - Add nuget.org as fallback package source for connectivity issues Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
AArnott
left a comment
There was a problem hiding this comment.
Looks really good. Just a few changes please.
…ve problematic test Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
…p mock file Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Updated [Microsoft.Bcl.AsyncInterfaces](https://github.com/dotnet/dotnet) from 10.0.9 to 10.0.10. <details> <summary>Release notes</summary> _Sourced from [Microsoft.Bcl.AsyncInterfaces's releases](https://github.com/dotnet/dotnet/releases)._ No release notes found for this version range. Commits viewable in [compare view](https://github.com/dotnet/dotnet/commits). </details> Updated [Microsoft.Bcl.Memory](https://github.com/dotnet/dotnet) from 10.0.9 to 10.0.10. <details> <summary>Release notes</summary> _Sourced from [Microsoft.Bcl.Memory's releases](https://github.com/dotnet/dotnet/releases)._ No release notes found for this version range. Commits viewable in [compare view](https://github.com/dotnet/dotnet/commits). </details> Updated [Microsoft.Bcl.TimeProvider](https://github.com/dotnet/dotnet) from 10.0.9 to 10.0.10. <details> <summary>Release notes</summary> _Sourced from [Microsoft.Bcl.TimeProvider's releases](https://github.com/dotnet/dotnet/releases)._ No release notes found for this version range. Commits viewable in [compare view](https://github.com/dotnet/dotnet/commits). </details> Updated [Microsoft.CodeAnalysis.Analyzers](https://github.com/dotnet/roslyn) from 5.3.0 to 5.6.0. <details> <summary>Release notes</summary> _Sourced from [Microsoft.CodeAnalysis.Analyzers's releases](https://github.com/dotnet/roslyn/releases)._ No release notes found for this version range. Commits viewable in [compare view](https://github.com/dotnet/roslyn/commits). </details> Updated Microsoft.CodeAnalysis.CSharp from 5.3.0 to 5.6.0. Updated Microsoft.CodeAnalysis.CSharp.Workspaces from 5.3.0 to 5.6.0. Updated [Microsoft.Extensions.ObjectPool](https://github.com/dotnet/dotnet) from 10.0.9 to 10.0.10. <details> <summary>Release notes</summary> _Sourced from [Microsoft.Extensions.ObjectPool's releases](https://github.com/dotnet/dotnet/releases)._ No release notes found for this version range. Commits viewable in [compare view](https://github.com/dotnet/dotnet/commits). </details> Updated [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 18.5.1 to 18.8.1. <details> <summary>Release notes</summary> _Sourced from [Microsoft.NET.Test.Sdk's releases](https://github.com/microsoft/vstest/releases)._ ## 18.8.1 ## What's Changed * Fix protocol negotiation timeout when STJ reflection is disabled (18.8.1) by @nohwnd in microsoft/vstest#16281 **Full Changelog**: microsoft/vstest@v18.8.0...v18.8.1 ## 18.8.0 ## What's Changed * Migrate from Newtonsoft.Json to System.Text.Json / Jsonite (merge to main) by @nohwnd in microsoft/vstest#15687 - For more detail refer to https://devblogs.microsoft.com/dotnet/vs-test-is-removing-its-newtonsoft-json-dependency/ * Create source-only filter package by @Youssef1313 in microsoft/vstest#15638 * Add ARM64 msdia140.dll support to test platform packages by @nohwnd in microsoft/vstest#15692 * Fix mutex cleanup crash on macOS/Linux by @nohwnd in microsoft/vstest#15684 * Restrict artifact temp directory permissions on Unix by @nohwnd in microsoft/vstest#15729 * Add support for filtering uncategorized tests with TestCategory=None by @Evangelink in microsoft/vstest#15727 * Fix SCI binding failure in DTA hosts (main) by @nohwnd in microsoft/vstest#15724 * Fix HTML logger parallel file collision by @nohwnd in microsoft/vstest#15435 * Improve error message when testhost cannot be found by @nohwnd in microsoft/vstest#16053 * Fix HTML logger exception on invalid XML chars in test display names by @nohwnd in microsoft/vstest#16051 **Full Changelog**: microsoft/vstest@v18.7.0...v18.8.0 ## 18.7.0 ## What's Changed * Add ARM64 msdia140.dll support to test platform packages by @jamesmcroft in microsoft/vstest#15689 * Update System.Memory from 4.5.5 to 4.6.3 by @nohwnd in microsoft/vstest#15706 ## New Contributors * @jamesmcroft made their first contribution in microsoft/vstest#15689 **Full Changelog**: microsoft/vstest@v18.6.0...v18.7.0 ## 18.6.0 ## What's Changed * Revert removal of Video Recorder by @nohwnd in microsoft/vstest#15336 * Speed up blame by filtering non-.NET processes from dump collection by @nohwnd in microsoft/vstest#15518 * Add README.md to NuGet packages by @nohwnd in microsoft/vstest#15550 * Report child process info on connection timeout by @nohwnd in microsoft/vstest#15603 ### Changes to tests and infra * Brand as 18.6 by @nohwnd in microsoft/vstest#15423 * Upgrading code coverage version to 18.5.1, by @fhnaseer in microsoft/vstest#15422 * Updating System.Collections.Immutable to 9.0.11 by @MSLukeWest in microsoft/vstest#15425 * Fix attachVS when used for debugging integration tests by @nohwnd in microsoft/vstest#15451 * Replace dotnet.config, with global.json by @nohwnd in microsoft/vstest#15449 * Document debugging integration tests with AttachVS by @Copilot in microsoft/vstest#15452 * Fix stack overflow tests by @nohwnd in microsoft/vstest#15461 * Make TestAssets.sln buildable locally by @Youssef1313 in microsoft/vstest#15466 * Try filtering out tests by @nohwnd in microsoft/vstest#15463 * Build just once when tfms run in parallel by @nohwnd in microsoft/vstest#15465 * Review simplify compatibility sources, deduplicate tests by @nohwnd in microsoft/vstest#15472 * Cleanup dead TRX code by @Youssef1313 in microsoft/vstest#15474 * Update .NET runtimes to 8.0.25, 9.0.14, and 10.0.4 by @nohwnd in microsoft/vstest#15481 * Compat matrix checker by @nohwnd in microsoft/vstest#15480 * Add trx analysis skill by @nohwnd in microsoft/vstest#15486 * Split integration tests to single tfm and multi tfm project by @nohwnd in microsoft/vstest#15484 * Update matrix by @nohwnd in microsoft/vstest#15477 * Break infinite restore loop in VS by @nohwnd in microsoft/vstest#15503 * Use global package cache for build, and local for running integration tests by @nohwnd in microsoft/vstest#15500 * Update contributing by @nohwnd in microsoft/vstest#15505 * Reduce test wall-clock time by increasing minThreads by @drognanar in microsoft/vstest#15502 * Indicator flakiness by @nohwnd in microsoft/vstest#15513 * Fix ci build by @nohwnd in microsoft/vstest#15515 * Fix thread safety issues by @Evangelink in microsoft/vstest#15512 * Optimize DotnetSDKSimulation_PostProcessing test (163s → 61s) by @nohwnd in microsoft/vstest#15516 * Build isolated test assets for single TFM instead of 7 by @nohwnd in microsoft/vstest#15517 * Remove unused dependencies from Library.IntegrationTests by @nohwnd in microsoft/vstest#15527 * Remove printing _attachments content to console by @nohwnd in microsoft/vstest#15520 * Add Linux/macOS test filtering guide to CONTRIBUTING.md by @nohwnd in microsoft/vstest#15521 * Change integration test parallelization from ClassLevel to MethodLevel by @nohwnd in microsoft/vstest#15526 * Unify target framework checks with IsNetFrameworkTarget/IsNetTarget by @nohwnd in microsoft/vstest#15523 * Add unattended work instructions to copilot-instructions.md by @nohwnd in microsoft/vstest#15531 * Reduce code style rule severity from warning to suggestion by @nohwnd in microsoft/vstest#15522 * Remove Debug/Release line number branching from tests by @nohwnd in microsoft/vstest#15519 * Revise unattended work instructions in copilot-instructions.md by @nohwnd in microsoft/vstest#15532 * Improve CompatibilityRowsBuilder error message with diagnostic details by @nohwnd in microsoft/vstest#15529 * docs: add git worktree and upstream sync workflow to copilot-instructions.md by @nohwnd in microsoft/vstest#15538 * Add VSIX runner to smoke tests by @nohwnd in microsoft/vstest#15541 * Remove deprecated WebTest and TMI test methods by @nohwnd in microsoft/vstest#15525 * Fix compatibility test failures for legacy vstest.console and MSTest adapter by @nohwnd in microsoft/vstest#15534 * Convert TestPlatform.sln to slnx format by @nohwnd in microsoft/vstest#15551 * Convert test/TestAssets .sln files to .slnx format by @nohwnd in microsoft/vstest#15557 ... (truncated) Commits viewable in [compare view](microsoft/vstest@v18.5.1...v18.8.1). </details> Updated [Microsoft.VisualStudio.Threading](https://github.com/microsoft/vs-threading) from 17.14.15 to 18.7.23. <details> <summary>Release notes</summary> _Sourced from [Microsoft.VisualStudio.Threading's releases](https://github.com/microsoft/vs-threading/releases)._ ## 18.7.23 ## What's Changed ### Fixes * Fix `CancellationToken.Combine` with 3+ cancelable tokens by @AArnott in microsoft/vs-threading#1443 * Fix VSTHRD110 firing in Expression-valued scenarios by @AArnott with @Copilot in microsoft/vs-threading#1467 * Fix super set for VSTHRD103 by @AArnott in microsoft/vs-threading#1545 * Fix VSTHRD114 not firing for null in ternary conditional expressions by @AArnott with @Copilot in microsoft/vs-threading#1548 * Disable VSTHRD010 in AppWithoutMainThread.editorconfig by @ArturDorochowicz in microsoft/vs-threading#1562 * Fix VSTHRD103 missing diagnostic for sync extension methods with async alternatives in the same static class by @drewnoakes with @Copilot in microsoft/vs-threading#1569 ### Enhancements * Add `JoinableTaskFactory.DisableProcessing()` by @AArnott in microsoft/vs-threading#1576 * Add `NoMessagePumpSyncContext..ctor(SynchronizationContext)` for Post/Send behaviors by @AArnott in microsoft/vs-threading#1578 * Add trim and NativeAOT safety attributes by @AArnott in microsoft/vs-threading#1471 * Add `IPendingExecutionRequestState` interface to expose completion state of `SingleExecuteProtector` by @lifengl in microsoft/vs-threading#1447 * Add AdditionalFiles support to VSTHRD103 analyzer for excluding specific APIs by @AArnott with @Copilot in microsoft/vs-threading#1465 * Document InvalidOperationException for AsyncReaderWriterLock acquisition methods by @AArnott with @Copilot in microsoft/vs-threading#1466 * Allow library code to detect the JoinableTaskContext is not associated with Main thread by @lifengl in microsoft/vs-threading#1477 * remove NotifyOfCrossThreadDependency call inside get_NoMessagePumpSynchronizationContext by @lifengl in microsoft/vs-threading#1486 * reduce overhead when running in no main thread mode by @lifengl in microsoft/vs-threading#1502 * Join tasks waited by JoinableTaskCollection.JoinUntilEmpty in dumpasync result by @lifengl in microsoft/vs-threading#1538 * Remove slow regex from threading analyzers by @AArnott in microsoft/vs-threading#1547 ## New Contributors * @jgrosic made their first contribution in microsoft/vs-threading#1485 * @AbhitejJohn made their first contribution in microsoft/vs-threading#1533 * @ArturDorochowicz made their first contribution in microsoft/vs-threading#1562 * @microsoft-github-policy-service[bot] made their first contribution in microsoft/vs-threading#1587 **Full Changelog**: microsoft/vs-threading@v17.14.15...v18.7.23 Commits viewable in [compare view](microsoft/vs-threading@v17.14.15...v18.7.23). </details> Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: The Keeper of the Crypto Hives <235137155+cryptohivekeeper@users.noreply.github.com>
The VSTHRD103 analyzer flags calls to synchronous methods where asynchronous equivalents exist when in an async context. However, some APIs have async versions that are significantly slower, less efficient, or simply inappropriate for certain use cases.
This PR adds the ability to exclude specific APIs from VSTHRD103 diagnostics using AdditionalFiles, following the same pattern established by the VSTHRD010 analyzer.
Changes
Core Implementation
FileNamePatternForSyncMethodsToExcludeFromVSTHRD103regex pattern for the new configuration fileMethodAnalyzerfrom static to instance-based to store excluded methodsCommonInterest.ReadMethods()andQualifiedMember.IsMatch()for consistencyConfiguration
Users can now create a file named
vs-threading.SyncMethodsToExcludeFromVSTHRD103.txtwith the following format:Documentation
configuration.mdwith details about the new configuration optionVSTHRD103.mdto reference the configuration capabilityTesting
Example Usage
Before this change, calling
SqlDataReader.Read()in an async method would always generate a VSTHRD103 warning even thoughReadAsync()might be inappropriate for the use case.With this change, teams can exclude such methods:
Success Metrics
✅ Reuses existing parser: Uses the same
CommonInterest.ReadMethods()infrastructure as VSTHRD010✅ Comprehensive testing: Added tests verifying diagnostics are suppressed for excluded APIs while preserved for others
Fixes #1464.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
1elvsblobprodwus2177.vsblob.vsassets.iodotnet build src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj(dns block)2wrvsblobprodwus2180.vsblob.vsassets.iodotnet build src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj(dns block)5o1vsblobprodwus2115.vsblob.vsassets.iodotnet build src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj(dns block)78kvsblobprodwus2152.vsblob.vsassets.iodotnet build src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj(dns block)abcvsblobprodwus2161.vsblob.vsassets.iodotnet build src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj(dns block)i01vsblobprodwus216.vsblob.vsassets.iodotnet build src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj(dns block)jlovsblobprodwus2163.vsblob.vsassets.iodotnet build src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj(dns block)nypvsblobprodwus2178.vsblob.vsassets.iodotnet build src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj(dns block)tn2vsblobprodwus2124.vsblob.vsassets.iodotnet build src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj(dns block)vd2vsblobprodwus2150.vsblob.vsassets.iodotnet build src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj(dns block)xktvsblobprodwus2141.vsblob.vsassets.iodotnet build src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj(dns block)xofvsblobprodwus2114.vsblob.vsassets.iodotnet build src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj(dns block)y1mvsblobprodwus2138.vsblob.vsassets.iodotnet build src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj(dns block)If you need me to access, download, or install something from one of these locations, you can either: